package nl.utwente.eemcs.graph;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Class containing a list with processes and a list with edges between the processes, which describe the communication and data dependency relations between the processes
 * @author Evert Duipmans
 */
public class GraphCollaboration {
	/**
	 * List with processes
	 */
	private List<Graph> processes = new ArrayList<Graph>();
	
	/**
	 * List with communication edges
	 */
	private Set<Edge> communicationEdges = new HashSet<Edge>();
	
	/**
	 * List with data edges
	 */
	private Set<Edge> dataEdges = new HashSet<Edge>();	
	
	/**
	 * List with all the data restriction errors
	 */
	private HashMap<String, HashSet<Node>> dataRestrictionErrors = new HashMap<String, HashSet<Node>>();
	
	/**
	 * The startup process
	 */
	private Graph mainProcess;
	
	public GraphCollaboration(List<Graph> processes,
			Set<Edge> communicationEdges, Set<Edge> dataEdges, Graph mainProcess) {
		super();
		this.processes = processes;
		this.communicationEdges = communicationEdges;
		this.dataEdges = dataEdges;
		this.mainProcess = mainProcess;
	}	
	
	public Graph getMainProcess() {
		return mainProcess;
	}

	public void setMainProcess(Graph mainProcess) {
		this.mainProcess = mainProcess;
	}

	public List<Graph> getProcesses() {
		return processes;
	}
	
	public void setProcesses(List<Graph> processes) {
		this.processes = processes;
	}
	
	public Set<Edge> getDataEdges() {
		return this.dataEdges;
	}
	
	public void setDataEdges(HashSet<Edge> edges) {
		this.dataEdges = edges;
	}
	
	public Set<Edge> getCommunicationEdges() {
		return this.communicationEdges;
	}
	
	public void setCommunicationEdgesEdges(HashSet<Edge> edges) {
		this.communicationEdges = edges;
	}
	
	public void addDataRestrictionError(String dataItem, Node n) {
		HashSet<Node> nodes;
		if (dataRestrictionErrors.containsKey(dataItem))
			nodes = dataRestrictionErrors.get(dataItem);
		else {
			nodes = new HashSet<Node>();
			dataRestrictionErrors.put(dataItem, nodes);
		}
		nodes.add(n);
	}
	
	public HashMap<String, HashSet<Node>> getDataRestrictionErrors() {
		return this.dataRestrictionErrors;
	}
	
	public boolean nodeViolatesDataRestriction(Node n) {
		for (String dataItem : dataRestrictionErrors.keySet()) {
			if (dataRestrictionErrors.get(dataItem).contains(n))
				return true;
		}
		return false;
	}
}